#include <iostream>
#include <cstring>
#include <set>
#define MAXN 50
#define INF 1 << 20
using namespace std;
int N, T;
int path[MAXN][MAXN];
void solve();
int dp[MAXN][MAXN];

int main() {
    while (cin >> N && N != 0) {
        T = 0;
        memset(path, -1, sizeof path);
        int a, b, c;
        for (int i = 0; i < N; i++) {
            cin >> a >> b >> c;
            T = max(T, max(a, b));
            path[a][b] = c; path[b][a] = c;
        }
        solve();
    }
}

void solve() {
    for (int i = 0; i <= T; i++) {
        for (int j = 0; j <= T; j++) {
            if (i == j) dp[i][j] = 0;
            else if (path[i][j] != -1) dp[i][j] = dp[j][i] = path[i][j];
            else dp[i][j] = dp[j][i] = INF;
        }
    }

    for (int k = 0; k <= T; k++) {
        for (int i = 0; i <= T; i++) {
            for (int j = 0; j <= T; j++) {
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
            }
        }
    }

    int res, dis = INF;
    for (int i = 0; i <= T; i++) {
        int d = 0;
        for (int j = 0; j <= T; j++) {
            d += dp[i][j];
        }
        if (d < dis) {
            dis = d; res = i;
        }
    }

    cout << res << " " << dis << endl;
}